﻿using System;
using System.Collections.Generic;
using System.Text;
using JKZP.Model;
using System.Data;
using System.Data.OracleClient;

namespace JKZP.DAL
{
    public class BLACKDAL
    {
        private BlackTable ToCustomer(DataRow row)
        {
            BlackTable bt = new BlackTable();
            bt.Hphm = (string)row["HPHM"];
            bt.Clms = (string)row["CLMS"];
            return bt;
        }
        public BlackTable[] GetAll()
        {
            DataTable table = new DataTable();
            table = SqlHelper.ExecuteDataTable("select hphm,clms from blacKtable");
            BlackTable[] bts = new BlackTable[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow row = table.Rows[i];
                bts[i] = ToCustomer(row);
            }
            return bts;
        }

        public string GetById(string hphm)
        {
            DataTable dt = SqlHelper.ExecuteDataTable(@"select clms from blacKtable 
                    where hphm=:hphm",
                new OracleParameter(":hphm", hphm));
            if (dt.Rows.Count <= 0)
            {
                return null;
            }
            else if (dt.Rows.Count > 1)
            {
                throw new Exception("严重错误，查出多条数据！");
            }
            else
            {
                DataRow row = dt.Rows[0];
                string value = row[0].ToString();
                return value;
            }
        }

    }
}
